<template>
    <view>
        <view style="font-size: 13px;color: #999999;margin: 10px">
            提示: 收藏最多保存100个宝贝，如果超出100个宝贝，如果此时收藏了新的宝贝，最末尾的宝贝将会自动删除
        </view>
<!--        <view style="margin:20px 30px 20px 30px">-->
<!--            <button size="large" round type="primary" style="background:#FC3F78;border: 1px solid #FC3F78" @click="remove()">全部删除</button>-->
<!--        </view>-->
        <view class="index-content">
            <view class="index-coupon has-bg-white has-pd-10 top_30">
                <view class="goods-list" v-if="couponlist.length > 0">
                    <orange-goods-list
                            v-for="(item,index) in couponlist"
                            :itemid="item.itemid"
                            :itempic="item.itempic+'_310x310.jpg'"
                            :tkmoney='"返现 ￥"+item.tkmoney'
							  :tkmoneys='item.tkmoneys'
                            :itemtitle="item.itemtitle"
                            :is-invitation="isInvitation"
                            :itemprice='"在售价 ¥"+item.itemprice'
                            :itemsale='item.itemsale'
                            :itemendprice="item.itemendprice"
                            :couponmoney="item.couponmoney"
                    ></orange-goods-list>
                </view>
            </view>
            <!-- 悬浮上拉 -->
            <view class="scroll_top" @tap="topScrollTap" v-bind:class="[scrollTop ? 'active' : '','']"
                  style="bottom: 56px;">
                <text class="iconfont icon-shangla"></text>
            </view>
            <!-- 空白页 -->
            <empty v-if="couponlist.length === 0" des="你还没有收藏商品，快去逛逛吧"></empty>
        </view>
    </view>
</template>

<script>
    export default {
        onShareAppMessage(res) {
            return {
                title: '购物先领券，一年省一半',
                path: '/pages/index/index'
            }
        },
        data() {
            return {
                couponlist: [],
                loadingType: 0,
                isInvitation:0,
                scrollTop: false,
                collectKey: 'orange-sqx-collect',

            }
        },
        onLoad: function (e) {
           // this.couponlist = this.$queue.get(this.collectKey);
            this.$queue.get(this.collectKey).forEach(d => {
                let grade = this.$queue.getData("grade");
				d.tkmoneys = (d.tkmoney * 0.7).toFixed(2);
                if (grade) {
                    d.tkmoney = (d.tkmoney * parseFloat(grade)).toFixed(2);
                } else {
                    d.tkmoney = (d.tkmoney * 0.3).toFixed(2);
                }
                d.itemsale = d.itemsale > 10000 ? (d.itemsale / 10000).toFixed(1) + "万" : d.itemsale;
                this.couponlist.push(d);
            });
            let userId = this.$queue.getData("userId");
            if (userId) {
                this.$Request.getT("/user/" + userId).then(res => {
                    if (res.status === 0) {
                        this.$queue.setData("image_url", res.data.image_url);
                        this.$queue.setData("mobile", res.data.phone);
                        this.isInvitation = res.data.isInvitation;
                        this.$queue.setData("isInvitation", res.data.isInvitation);
                        this.$queue.setData("relation", res.data.invitation);
                        this.$queue.setData("grade", res.data.grade);
                        this.$queue.setData("nickName", res.data.nickName);
                        this.$queue.setData("relation_id", res.data.relationId);
                        this.$queue.setData("gender", parseInt(res.data.gender));
                    }
                });
            }
        },
        onPullDownRefresh: function () {
            this.couponlist = this.$queue.get(this.collectKey);
            uni.stopPullDownRefresh(); // 停止刷新
        },
        methods: {
            remove() {
                this.$queue.remove(this.collectKey);
                this.couponlist = this.$queue.get(this.collectKey);
            },
            topScrollTap: function () {
                uni.pageScrollTo({
                    scrollTop: 0,
                    duration: 300
                });
            },
            onPageScroll: function (e) {
                this.scrollTop = e.scrollTop > 200;
            },

            toGoodsInfo: function (itemid) {
               let relation_id = this.$queue.getData("relation_id");
                if (relation_id) {
                    uni.navigateTo({
                        url: "/pages/detail/goodsinfo?itemid=" + itemid + "&relation_id=" + relation_id,
                    })
                } else {
                    uni.navigateTo({
                        url: "/pages/detail/goodsinfo?itemid=" + itemid,
                    })
                }
            },
        },

    }
</script>

<style>
    @import "../../static/css/index.css";
</style>
